unit Rails.ActiveRecord.Attributes;

interface

uses
  System.SysUtils;

type
  TRailsDBValidate = (NoUpdate, NoInsert, Lazy, Required);
  TRailsValidate = (rvZeros, //Preenche o tamanho do campo com Zeros
                    rvPassWord, //Esconde o que foi digitado pelo Usuario
                    rvMoney, //Formata com R$
                    rvPercentual //Formata com %
                    );

  TRailsDBValidations = set of TRailsDBValidate;
  TRailsValidations = set of TRailsValidate;

{$REGION 'RailsColumn'}
  RailsColumn = class(TCustomAttribute)
  private
    FDisplayName: string;
    FValidations: TRailsValidations;
  public
    property DisplayName: string read FDisplayName;
    property Validations: TRailsValidations read FValidations;
    constructor Create(const ADisplayName: string; const AValidations: TRailsValidations = []); overload;
  end;
{$ENDREGION}

{$REGION 'RailsCalculated'}
  RailsCalculated = class(RailsColumn)
  private
    FColumnName: string;
    FLength: Int8;
    FPrecision: Int8;
    FScale: Int8;
  public
    property Length: Int8 read FLength;
    property Precision: Int8 read FPrecision;
    property Scale: Int8 read FScale;
    property ColumnName: string read FColumnName;
    constructor Create(const AColumnName, ADisplayName: string; ALength: Int8; AValidations: TRailsValidations = []); overload;
    constructor Create(const AColumnName, ADisplayName: string; APrecision, AScale: Int8; AValidations: TRailsValidations = []); overload;
  end;
{$ENDREGION}

{$REGION 'RailsEnumeration'}
  RailsEnumeration = class(TCustomAttribute)
  private
    FTitles: string;
  public
    property Titles: string read FTitles;
    constructor Create(ATitles: string);
  end;
{$ENDREGION}

{$REGION 'BooleanValues'}
  BooleanValues = class(TCustomAttribute)
  public
    True: string;
    False: string;
    constructor Create(const ATrue, AFalse: string);
    function GetValue(const AValue: Boolean): string;
  end;
{$ENDREGION}

{$REGION 'CharsOnly'}
  CharsOnly = class(TCustomAttribute)
  private
    FChars: TSysCharSet;
  public
    property Chars: TSysCharSet read FChars;
    constructor Create(AChars: TSysCharSet);
  end;
{$ENDREGION}

{$REGION 'Equal, LessThan, GreaterThan, Between'}
  Equal = class(TCustomAttribute)
  private
    FValue: Double;
  public
    property Value: Double read FValue;
    constructor Create(AValue: Double);
  end;
  LessThan = class(Equal)
  end;
  GreaterThan = class(Equal)
  end;

  Between = class(TCustomAttribute)
  private
    FMin: Double;
    FMax: Double;
  public
    property Min: Double read FMin;
    property Max: Double read FMax;
    constructor Create(MinValue, MaxValue: Double);
  end;

{$ENDREGION}

implementation

{$REGION 'RailsColumn' }
{ RailsColumn }

constructor RailsColumn.Create(const ADisplayName: string;
  const AValidations: TRailsValidations);
begin
  FDisplayName := ADisplayName;
  FValidations := AValidations;
end;
{$ENDREGION}

{$REGION 'RailsCalculated' }
{ RailsCalculated }

constructor RailsCalculated.Create(const AColumnName, ADisplayName: string;
  ALength: Int8; AValidations: TRailsValidations);
begin
  inherited Create(ADisplayName, AValidations);
  FColumnName := AColumnName;
  FLength := ALength;
end;

constructor RailsCalculated.Create(const AColumnName, ADisplayName: string;
  APrecision, AScale: Int8; AValidations: TRailsValidations);
begin
  inherited Create(ADisplayName, AValidations);
  FColumnName := AColumnName;
  FPrecision := APrecision;
  FScale := AScale;
end;

{$ENDREGION}

{$REGION 'RailsEnumetarion' }
{ RailsEnumetarion }

constructor RailsEnumeration.Create(ATitles: string);
begin
  FTitles := ATitles;
end;

{$ENDREGION}

{$REGION 'BooleanValues' }

{ BooleanValues }

constructor BooleanValues.Create(const ATrue, AFalse: string);
begin
  True := ATrue;
  False := AFalse;
end;

function BooleanValues.GetValue(const AValue: Boolean): string;
begin
  if AValue then
    Result := True
  else
    Result := False;
end;

{$ENDREGION}

{$REGION 'Equal'}

{ Equal }

constructor Equal.Create(AValue: Double);
begin
  FValue := AValue;
end;

{$ENDREGION}

{$REGION 'Between'}

{ Between }

constructor Between.Create(MinValue, MaxValue: Double);
begin
  FMin := MinValue;
  FMax := MaxValue;
end;

{$ENDREGION}

{$REGION 'CharsOnly'}

{ CharsOnly }

constructor CharsOnly.Create(AChars: TSysCharSet);
begin
  FChars := AChars;
end;

{$ENDREGION}

end.
